using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Collections;
using System.Configuration;

namespace SymAutomate
{
    /// <summary>
    /// Parses and gives access to console command line arguments.
    /// Class only provides minimal format error checking.
    /// Error Numbers 100-149; Reference file ErrorNumbers.txt for more information.
    /// 100 Error: %Argument% Invalid Argument Format. Use /h switch for help.
    /// 101 Error: Duplicate Argument. Use /h switch for help.
    /// </summary>
    class ConsoleArguments
    {
        private Hashtable __ArgumentCollection = new Hashtable();

        public Hashtable ArgumentCollection { get { return __ArgumentCollection; } }

        public ConsoleArguments(string[] args)
        {
            //check each argument one at a time
            for (int i = 0; i < args.Length; i++)
            {
                string _Argument = args[i];
                if (_Argument.Contains(@"="))
                {
                    //split the argument to command and value
                    string[] _ArgumentParts = _Argument.Split('=');
                    if (_ArgumentParts.Length != 2)
                    {
                        throw new ReturnException("100 Error: '" + _Argument + "' Invalid Argument Format. Use /h switch for help.");
                    }

                    if (!__ArgumentCollection.Contains(_ArgumentParts[0].ToLower()))
                    {
                        __ArgumentCollection.Add(_ArgumentParts[0].ToLower(), _ArgumentParts[1]);
                    }
                    else
                    {
                        throw new ReturnException("101 Error: Duplicate Argument. Use /h switch for help.");
                    }
                }
                else
                {
                    throw new ReturnException("100 Error: '" + _Argument + "' Invalid Argument Format. Use /h switch for help.");
                }
            }
        }
    }
}
